﻿using System.Threading.Tasks;
using tencentyun;
using TimServerSDK.Accounts;
using TimServerSDK.Core;
using TimServerSDK.Friends;
using TimServerSDK.Groups;
using TimServerSDK.Portraits;

namespace TimServerSDK
{
    public class TimServerApi : ITimServerApi
    {
        private readonly ITimServerOptionsFun _optionsFun;
        public IAccountTimServerApi AccountApi { get; }
        public IFriendTimServerApi FriendApi { get; }
        public IGroupTimServerApi GroupApi { get; }
        public IPortraitTimServerApi PortraitApi { get; }

        public TimServerApi(
            ITimServerOptionsFun optionsFun,
            IAccountTimServerApi accountApi,
            IFriendTimServerApi friendApi,
            IGroupTimServerApi groupApi,
            IPortraitTimServerApi portraitApi)
        {
            AccountApi = accountApi;
            FriendApi = friendApi;
            GroupApi = groupApi;
            PortraitApi = portraitApi;
            _optionsFun = optionsFun;
        }

        public Task<TimServerOptions> GetOptionsAsync()
        {
            return _optionsFun.GetOptionsAsync();
        }

        public async Task<string> GenSigAsync(string identifier, int expire = 15552000)
        {
            var options = await _optionsFun.GetOptionsAsync();

            var sigApi = new TLSSigAPIv2(options.AppId, options.AppSecret);
            return sigApi.GenSig(identifier, expire);
        }
    }
}
